package com.ppm.server.user.service.impl;

import com.ppm.common.base.dto.ResultDTO;
import com.ppm.common.base.entity.UserInfo;
import com.ppm.common.base.exception.BaseException;
import com.ppm.common.base.util.IdWorker;
import com.ppm.server.user.dto.UserInfoDTO;
import com.ppm.server.user.dto.UserQueryConditionDTO;
import com.ppm.server.user.mapper.UserInfoMapper;
import com.ppm.server.user.service.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * @author KwokChiKit
 * @date 2021/4/29 10:40
 * @Description 用户信息功能类
 */
@Transactional(rollbackFor = Exception.class)
@Service
@Slf4j
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public ResultDTO saveUser(UserInfo userInfo) {
        userInfo.setId(IdWorker.getId());
        int result = userInfoMapper.insertSelective(userInfo);
        if (result == 0) {
            return ResultDTO.failed("添加失败");
        }
        return ResultDTO.requestSuccess();
    }

    @Override
    public List<UserInfoDTO> getUserList(UserQueryConditionDTO userQueryConditionDTO) {
        if (userQueryConditionDTO == null) {
            userQueryConditionDTO = new UserQueryConditionDTO();
        }
        List<UserInfoDTO> userInfoDTOS = userInfoMapper.getUserList(userQueryConditionDTO);
        return userInfoDTOS;
    }

}
